package cloud.maque.admin.impl;

import cloud.maque.admin.domain.entity.MqWorktime;
import cloud.maque.admin.mapper.MqWorktimeMapper;
import cloud.maque.admin.service.MqWorktimeService;
import cloud.maque.framework.common.request.PaginateDataResquest;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 4color
 * @description mq_worktime
 * @date 2023-03-17
 */
@Service
public class MqWorktimeServiceImpl extends ServiceImpl<MqWorktimeMapper, MqWorktime> implements MqWorktimeService {
    @Override
    public MqWorktime insert(MqWorktime worktime) {

        save(worktime);
        return worktime;
    }

    @Override
    public PageInfo<MqWorktime> page(PaginateDataResquest<MqWorktime> pageReq) {

        PageHelper.startPage(pageReq.getPageIndex(), pageReq.getPageSize());
        QueryWrapper<MqWorktime> wrapper = new QueryWrapper<>();


        if (!StrUtil.isEmptyIfStr(pageReq.getData().getTenantId())) {
            wrapper.lambda().eq(MqWorktime::getTenantId, pageReq.getData().getTenantId());
        }

        wrapper.lambda().orderByAsc(MqWorktime::getStartDate);
        wrapper.lambda().orderByAsc(MqWorktime::getWorktimeId);
        List<MqWorktime> lists = this.baseMapper.selectList(wrapper);
        PageInfo<MqWorktime> pageInfo = new PageInfo<>(lists);

        return pageInfo;
    }
}
